package com.geek.aop.introductions.aspect;

import com.geek.aop.introductions.services.MultipleCalculate;
import com.geek.aop.introductions.services.impl.MultipleCalculateImpl;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareParents;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class AopAspect {

    /**增强CalculateServiceImpl添加一个类的所有方法*/
    @DeclareParents(value="com.geek.aop.services.impl.CalculateServiceImpl",
            defaultImpl=MultipleCalculateImpl.class)
    MultipleCalculate multipleCalculate;


    @Pointcut("execution(* com.geek.aop.services.CalculateService.*(..))")
    public void pointCut(){}

    @Before(value = "pointCut()")
    public void methodBefore(JoinPoint joinPoint) {
        String methodName = joinPoint.getSignature().getName();
        System.out.println("执行目标方法【"+methodName+"】的<前置通知>,入参"+ Arrays.asList(joinPoint.getArgs()));
    }
}
